package com.jvyou.mybatis.spring.mapper;

import com.jvyou.mybatis.session.SqlSession;
import org.springframework.beans.factory.FactoryBean;

import javax.annotation.Resource;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/15 16:48
 * @Description
 */
public class MapperFactoryBean<T> implements FactoryBean<T> {

    private final Class<T> mapperClazz;

    @Resource
    private SqlSession sqlSession;

    public MapperFactoryBean(Class<T> mapperClazz) {
        this.mapperClazz = mapperClazz;
    }

    @Override
    public T getObject() throws Exception {
        return sqlSession.getMapper(mapperClazz);
    }

    @Override
    public Class<?> getObjectType() {
        return mapperClazz;
    }
}
